﻿using QuanLyKho.DTO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace QuanLyKho.DAL
{
    class ChiTietHangHoaDAO : DataProvider
    {

        public void insert(ChiTietHangHoaDTO chiTietHangDTO)
        {
            string sqlString = "insert into ChiTietHangHoa values('"
                + chiTietHangDTO.MaHang + "','"
                + chiTietHangDTO.MaKho + "','"
                + chiTietHangDTO.MaNhaPhanPhoi + "','"
                + chiTietHangDTO.SoLuong + "','"
                + chiTietHangDTO.NgayNhap.ToShortDateString() + "','"
                + 0 + "')";
            ExecuteNonQuery(sqlString);
        }

        public ArrayList getListChiTietHang()
        {
            string sqlString = "Select * from ChiTietHangHoa";
            adapter = new OleDbDataAdapter(sqlString, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            ArrayList listHangHoa = ConvertDataSetToArrayList(dataSet);

            return listHangHoa;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            ChiTietHangHoaDTO chiTietHangHoaDTO = new ChiTietHangHoaDTO();
            chiTietHangHoaDTO.MaHang = dt.Rows[i]["MaHang"].ToString();
            chiTietHangHoaDTO.MaKho = dt.Rows[i]["MaKho"].ToString();
            chiTietHangHoaDTO.MaNhaPhanPhoi = dt.Rows[i]["MaNhaPhanPhoi"].ToString();
            chiTietHangHoaDTO.NgayNhap = DateTime.Parse(dt.Rows[i]["NgayNhap"].ToString());
            chiTietHangHoaDTO.SoLuong = Int32.Parse(dt.Rows[i]["SoLuong"].ToString());

            return (object) chiTietHangHoaDTO;
        }
    }
}
